﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace Agents.Agent
{
    public partial class SwitchCustomer : System.Web.UI.Page
    {
        //this page documents the switching of clients.
        //the agent must select/describe a reason for changing clients.
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        //function is activated whent the ok button is activated
        protected void okBtn_Click(object sender, EventArgs e)
        {
            //for holding the agents reason for changing clients
            string reason;
            Queries queries = new Queries();

            //if the agent wants to describe his own reason- save reason given in textbox.
            if (costumersCombo.SelectedItem.Text == "אחר")
            {
                reason = otherTxtbox.Text;
            }
            //otherwise- use reason chosen from combo.
            else
            {
                reason = costumersCombo.SelectedItem.Text;
            }

            //retrieving the client
            Clients client = queries.GetClient(Int32.Parse(Request.QueryString["clientId"]));

            // Retrieving the agent from the user
            Agents agent = queries.GetAgentByUserName(Page.User.Identity.Name);

            // Add to the agent's log that he left the client
            queries.AgentLeftClient(agent, "בחר לא לבקר את " +
                client.Name + ". סיבה: " + reason);
               
            queries.ChangeToActive(agent);
            Response.Redirect("AgentMenu.aspx");
        }

        //function redirects the agent to his "going to client" page
        protected void backBtn_Click(object sender, EventArgs e)
        {
            Response.Redirect("StartShiftDisplay.aspx?clientId=" + Request.QueryString["clientId"]);
        }
    }
}